﻿
Namespace AdvanceWars.Data
    ''' <summary>
    ''' 范围
    ''' </summary>
    <Serializable()>
    Public Class Range

        Public Shared NoneRange As Range = New Range(0, 0)

        Sub New()
            mMinRange = 1
            mMaxRange = 1
        End Sub

        Sub New(ByVal MinRange As Integer, ByVal MaxRange As Integer)
            If MinRange > MaxRange Then
                mMinRange = 0
                mMaxRange = 0
            Else
                mMinRange = MinRange
                mMaxRange = MaxRange
            End If
        End Sub

        Property MinRange As Integer
            Get
                Return mMinRange
            End Get
            Set(ByVal value As Integer)
                If value > 0 AndAlso value <= MaxRange Then
                    mMinRange = value
                Else
                    mMinRange = MaxRange
                End If
            End Set
        End Property
        Private mMinRange As Integer

        Property MaxRange As Integer
            Get
                Return mMaxRange
            End Get
            Set(ByVal value As Integer)
                If value > 0 AndAlso value >= MinRange Then
                    mMaxRange = value
                Else
                    mMaxRange = MinRange
                End If
            End Set
        End Property
        Private mMaxRange As Integer

        ReadOnly Property IsInRange(ByVal x As Integer) As Boolean
            Get
                Return x >= MinRange AndAlso x <= MaxRange
            End Get
        End Property

    End Class
End Namespace